文章目录

本文参考自:http://yijiebuyi.com/blog/f18d38eb7cfee860c117d629fdb16faf.html
生成不同的Key

  1. 执行如下命令生成一个key, 并指定其名字为 id_ras_aaa (否则为默认的id_ras,并会覆盖之前的值)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):/root/.ssh/id_rsa_aaa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa_aaa.
Your public key has been saved in /root/.ssh/id_rsa_aaa.pub.
The key fingerprint is:
9b:92:f6:1f:d2:72:bd:72:19:45:42:5f:e4:65:33:64 root@AY140122145815620396Z
The key's randomart image is:
+--[ RSA 2048]----+
| .. .E=|
| ..o++|
| o. .|
| . |
| S . |
| . + .. |
| + = + .o |
| . o +..o. |
| ...o. |
+-----------------+

公私钥文件放在 ~/.ssh文件夹下。同样操作,可以生成 id_ras_bbb

1.查看系统ssh-key代理,

1
2
3
4
5
$ ssh-add -l
Could not open a connection to your authentication agent.
如果发现上面的提示,说明系统代理里没有任何key,执行如下操作
exec ssh-agent bash

2.添加私钥至 ssh-agent

1
2
$ ssh-add ~/.ssh/id_rsa_aaa
$ ssh-add ~/.ssh/id_rsa_bbb

3.打开github 或者 开源中国 ssh 管理页面把 对应的公钥提交保存到代码管理服务器 (.pub 结尾)

4.在 ~/.ssh 目录创建或修改 config 配置文件:

1
2
3
4
5
6
7
8
9
10
`#aaa (github 配置)
``Host aaa
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_aaa
` #bbb (开源中国 配置)
Host bbb
HostName git.oschina.net
User git
IdentityFile ~/.ssh/id_rsa_bbb
文章目录